package cn.itcast.n8;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author: AirMan
 * @date: 2025/4/22 17:18
 * @description:
 */
public class TestScheduled {
    private static final Logger log = LoggerFactory.getLogger(TestScheduled.class);

    public static void main(String[] args) {

        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thursday = now.with(DayOfWeek.TUESDAY).withHour(18).withMinute(0).withSecond(0).withNano(0);
        if (now.compareTo(thursday) > 0) {
            thursday = thursday.plusWeeks(1);
        }
        System.out.println(thursday);
        long initialDelay = Duration.between(now, thursday).toMillis();
        long oneWeek = 7 * 24 * 60 * 60 * 10000L;

        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

        System.out.println("开始时间：" + new Date());
        executor.scheduleAtFixedRate(() -> {
            System.out.println("执行时间：" + new Date());
        }, initialDelay, oneWeek, TimeUnit.MILLISECONDS);

    }
}
